/**
 * 登录模块，提供登录相关业务功能
 * 
 * @Date: 2015-6-16
 * @author: Jackson wang
 * @version: 1.0
 * @since: 1.0
 */
define(["jquery", "datagridServ","msgServ", "ajaxServ", "formServ", "bizProto"],
		function($,datagridServ, msgServ, ajaxServ, formServ, bizProto) {

			'use strict';

			var _bizProto,
				//锚记datagrid目标元素
				$dg,
				//初始化后的datagrid dom对象
				$grid,
				//编辑弹窗对象及弹窗按钮对象
				$edit_window,window_btn,
				//设置密码弹窗对象及按钮对象
				$password_window,password_btn,
				//业务表单对象
				$form,
				//部门选择框字段
				$deptNameField, $deptIdField,formEl, formData = 0 
				
			var public_method = {				
				
				init:function(doc){
					private_method.init(doc);
				}
				
			}

			var private_method = {
				init : function(doc) {
					if (window.console) {
					console.info('workflowDeploy modules gets ready and been loaded.');
					}
					_bizProto = new bizProto({doc:doc,rootId:'panel-workflowDeploy',panelSelector:'div.well',subSystemCode:'workflow',moduleCode:'deploy'})
					private_method.initPath();
					private_method.initElement(_bizProto.pageDoc)
				},
				
				//初始化路径
				initPath:function(){
					
				},				
				
				//初始化元素
				initElement:function(doc){
					
					
					$dg = $(doc).find("#workflowDeploy-dg");
					$grid = $dg.datagrid({
						height:_bizProto.pageHeight,
						url : _bizProto.queryUrl,
						width : 'auto'						
					});
					
//					$grid.datagrid('load')

					// 绑定按钮事件
					var btn = $(doc).find('#tb-workflowDeploy a.function-btn')
					$(btn).unbind('click');
					$(btn).bind('click', function(e) {
						private_method.function_btn_listenner(e)
					})

					// 编辑窗口初始化
					$edit_window = $('#workflowDeploy-win')
					window_btn = $($edit_window).find('a.edit-window-btn')
					$(window_btn).unbind('click')
					$(window_btn).bind('click',	private_method.function_btn_listenner)
					$form = $($edit_window).find('form')
					
					
					
					// 搜索框
					$(doc).find("#searchbox").searchbox({
						menu : "#mm",
						prompt : '模糊查询',
						searcher : function(value, name) {
							var obj = {};
							obj["searchName"]=name;
							obj["searchValue"]=value;							
							$dg.datagrid('reload', obj);
						}

					});
					
					$.messager.progress('close');

				},
				
				setComboValue:function(node,target){
		    		if(node!=null){		    			
		    			$(target).val(node.text);
		    		}
		    	},
				// 功能按钮监听函数
				function_btn_listenner : function(e) {

					var _text;
					if (e != null) {
						e.preventDefault();
						_text = e.currentTarget.text

						if (_text != null) {
							switch (_text.trim()) {
								case "新增" :
									private_method.add();
									break;
								case "编辑" :
									private_method.edit(true);
									break;
								case "删除" :
									private_method.del();
									break;
								case "保存" :
									private_method.submit();
									break;
								case "取消" :
									private_method.cancel();
									break;
							}
						}

					}

				},
				// 新增函数
				add : function() {
					$form = $($edit_window).find('form')
					$($form).form('clear');
					$edit_window.window({width:800,height:600});
					$edit_window.window('open');
				},
				// 编辑,flag 为form按钮可见性标志
				edit : function(flag) {					
					var _param = {grid:$grid,window:$edit_window,width:800,height:600}
					datagridServ.edit(_param);
				},
				
				
				// 删除
				del : function() {
					
					datagridServ.delRow({url:_bizProto.delUrl,target:$grid});
				},
				// 提交form
				submit : function() {
					
					datagridServ.save({form:$form,grid:$grid,url:_bizProto.saveUrl})					
				},
				
				
				//
				cancel : function() {
					$($edit_window).window('close');
				}

			};

			
			return public_method;

		});